﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartSpace.Core;
using System.Data.Entity;
using SmartSpace.Cwt;

namespace SmartSpace.HopeHealth
{
	public class HopeHealthFactory: ICwtFactory, ICoreFactory
	{
        private string ConnectionString { get; set; }

        public HopeHealthFactory()
        {
            try
            {
                ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["hopehealth"].ConnectionString;
            }
            catch (Exception ex)
            {
                throw new System.Configuration.ConfigurationException("获取名为\"hopehealth\" 的连接字符串出错!", ex);
            }
        }

        //public HopeHealthFactory(string connectionString)
        //{
        //    ConnectionString = connectionString;
        //}

        CwtContext ICwtFactory.Get()
        {
            HopeHealthDbContext dbContext = new HopeHealthDbContext(ConnectionString);
            CwtContext context = new CwtContext(dbContext);
            return context;
        }

        CoreContext ICoreFactory.Get()
        {
            HopeHealthDbContext dbContext = new HopeHealthDbContext(ConnectionString);
            CoreContext context = new CoreContext(dbContext);
            return context;

        }
    }
}
